package org.com.curry.lee.utils.algorithm.algorithm;

import org.com.curry.lee.annotation.Strategy;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @description: 统一配置信息类
 * @author: lee_curry
 * @date: 2022/11/23
 */
@Component
public class DrawConfig {
    @Resource
    private List<IDrawAlgorithm> algorithmList;

    /**
     * 策略组
     */
    public static Map<Integer,IDrawAlgorithm> drawAlgorithmGroup = new ConcurrentHashMap<>();

    @PostConstruct
    public void init() {
        algorithmList.forEach(algorithm -> {
            Strategy strategy = AnnotationUtils.findAnnotation(algorithm.getClass(), Strategy.class);
            if (null != strategy) {
                drawAlgorithmGroup.put(strategy.strategyMode().getCode(), algorithm);
            }
        });
    }
}
